package com.ygy.yfzx.license.listener;//package com.ygy.yfzx.license.listener;

import com.ygy.yfzx.license.LicenseVerify;
import com.ygy.yfzx.license.config.LicenseProperties;
import com.ygy.yfzx.license.data.LicenseVerifyParam;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;


public class LicenseAppRunner implements ApplicationRunner {
    private LicenseProperties licenseProperties;

    public LicenseAppRunner(LicenseProperties licenseProperties) {
        this.licenseProperties = licenseProperties;
    }




    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println(" ApplicationRunner run " + licenseProperties);
        if ((null != licenseProperties && null != licenseProperties.getLicensePath())) {
            System.out.println("++++++++ 开始安装证书 ++++++++");
            LicenseVerifyParam param = new LicenseVerifyParam();
            param.setSubject(licenseProperties.getSubject());
            param.setPublicAlias(licenseProperties.getPublicAlias());
            param.setStorePass(licenseProperties.getStorePass());
            param.setLicensePath(licenseProperties.getLicensePath());
            param.setPublicKeysStorePath(licenseProperties.getPublicKeysStorePath());
            LicenseVerify licenseVerify = new LicenseVerify();
            //安装证书
            licenseVerify.install(param);
            System.out.println("++++++++ 证书安装结束 ++++++++");
        } else {
            System.out.println("++++++++ 开始安装证书 licensePath=null ++++++++");
        }
    }
}
